
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>行情数据</title>
    <!--导入layui相关的样式-->
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <!-- 导入layui函数库 -->
    <script src="../layui/layui.js" charset="utf-8"></script>
    <!--加载jQuery函数库-->
    <script src="../jQuery/jquery-1.11.2.js"></script>
    <!-- 注意：导入外部库的时候要注意改成自己的路径 -->
    <link rel="stylesheet" type="text/css" href="/css/font.css">
    <style>::-webkit-scrollbar{display: none;}</style>
</head>
<body>
<blockquote class="layui-elem-quote news_search">
<!-- 数据表格 -->
<table class="layui-hide" id="MarketTable" lay-filter="MarketList"></table>

<script type="text/html" id="Trans_search">
    <!--多条件查询层-->
    <div style="float: left">
        <form class="layui-form layui-col-md12 x-so">
            证券编号:
            <div  class="layui-input-inline">
                <input type="text" name="seID" id="seId" placeholder="请输入证券编号" autocomplete="off" class="layui-input" />
            </div>
            录入日期:
            <div  class="layui-input-inline">
                <input type="date" name="inputDate" id="tranDate" placeholder="请输入录入日期" autocomplete="off" class="layui-input"/>
            </div>
            <button id="search" class="layui-btn layui-btn-primary layui-bg-gray" lay-submit data-type="reload" lay-filter="provinceSearch">
                <i class="layui-icon">&#xe615;</i>
            </button>
        </form>
    </div>
    <!--多条件查询结束-->

    <!-- 表格头部上方工具栏 -->
    <div class="layui-btn-container layui-input-inline" style="padding-left: 150px">
        <b class="layui-btn layui-btn-sm layui-bg-blue" lay-event="lead_in_shang"><i class="layui-icon">&#xe67d;</i>导入交易所数据</b>
        <!--<b class="layui-btn layui-btn-sm layui-bg-blue" lay-event="add"><i class="layui-icon">&#xe67d;</i>导入深交所</b>-->
        <button class="layui-btn layui-btn-danger" lay-event="batchDel"><i class="layui-icon">&#xe640;</i>批量删除</button>
        <button class="layui-btn  layui-btn-normal" lay-event="add"><i class="layui-icon">&#xe654;</i>添加</button>
    </div>
</script>

<div  id="data-main" style="display: none;">
    <div style="margin-left: 120px;">
        <form class="layui-form" id="EquityForm" method="POST" lay-skin="line" lay-filter="EquityFormTest" style="margin-top: 50px;">
            <div class="layui-form-item">
                <label class="layui-form-label layui-icon">行情ID</label>
                <div class="layui-input-inline">
                    <input type="text" name="MarketId" lay-verify="required" placeholder="请输入行情数据ID" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label layui-icon">证券ID</label>
                <div class="layui-input-inline">
                    <input type="text" name="seId" lay-verify="required" placeholder="请输入证券ID" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label layui-icon">录入日期</label>
                <div class="layui-input-inline">
                    <input type="date" name="inputDate" lay-verify="required" placeholder="请输入录入日期" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label layui-icon">开盘价格</label>
                <div class="layui-input-inline">
                    <input type="text" name="openPrice" lay-verify="required" placeholder="请输入开盘价格" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label layui-icon">闭市价格</label>
                <div class="layui-input-inline">
                    <input type="text" name="closePrice" lay-verify="required" placeholder="请输入闭市价格" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label layui-icon">备注</label>
                <div class="layui-input-inline">
                    <input type="text" name="notes" lay-verify="required" placeholder="备注：例如：今天股票价格暴涨" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" style="margin-top: 50px;">
                <div class="layui-input-block" style="top: -20px;">
                    <button class="layui-btn layui-bg-blue" lay-submit lay-filter="formSave">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<!--导入上交所或者深交所弹出框-->
<div id="lead-in" style="display: none;">
    <form method="POST"  enctype="multipart/form-data" id="form1" action="/marketdates/form">
        <input id="upfile" type="file" class="layui-btn" name="upfile" style="background: #06b535;margin-left: 90px;margin-top: 30px;"><br> <br>
        <input type="submit" value="表单提交"  class="layui-btn" style="margin-left: 180px;margin-top: 30px;" onclick="return checkData()">
        <!-- <input type="button" value="ajax提交" id="btn" name="btn" >-->
    </form>
</div>

<!-- 行中操作按钮[仅对本行操作] -->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-normal layui-icon layui-icon-edit" lay-event="update">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-icon layui-icon-delete" lay-event="delete">删除</a>
</script>

<script type="text/javascript">
    layui.use(['table','layer','form','laypage','jquery','util'],function () {
        //导入模块并得到模块对象
        var table=layui.table,//表格对象
            layer=layui.layer,//弹层对象
            form=layui.form,//表单对象
            laypage=layui.laypage,//分页组件
            util=layui.util,//工具对象
            $=layui.jquery;//jquery 对象
        //渲染表格
        table.render({
            elem:"#MarketTable",
            url:"../json/MarketLXF.json",
            limit:15,//每页行数
            height:740,
            toolbar: '#Trans_search',//打印图标
            cols:[[
                {checkbox:true},//开启多选框
                {field:"MarketId",title:"行情编号",align:"center",sort:true},
                {field:"seId",title:"证券编号",align:"center"},
                {field:"inputDate",title:"录入日期",align:"center",templet:function (d) {
                        return util.toDateString(d.tranDate,"yyyy年MM月dd日 HH时:mm分:ss秒");
                    }},
                {field:"openPrice",title:"开盘价格(元)",align:"center"},
                {field:"closePrice",title:"闭市价格(元)",align:"center"},
                {field:"notes",title:"备注",align:"center"},
                {fixed: 'right', title:'操作', toolbar: '#barDemo',width:160}
            ]],
            page:true,
            limits: [5, 10,20,30,50]
        });
        //表格头部工具栏事件代码，根据lay-event属性值判断执行相应的代码
        table.on('toolbar(MarketList)',function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            //判断事件event值
            switch(obj.event) {
                case 'add':
                    //显示添加界面
                    method="add";
                    //清空表单
                    $("#EquityForm")[0].reset();
                    layer.open({
                        type: 1,//外部页面为2，内部层1
                        title: "<span style='color:white' align='center'><i class='layui-icon'>&#xe61f;</i>添加行情数据</span>",
                        area: ['40%', '70%'],
                        fix: false,
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'layui-layer-lan',
                        content:$("#data-main").html()
                    });
                    //将主键设置成允许修改[防止因先修改，后增加时，该字段被设置为只读]
                    $("input[name='rightsId']").prop("readonly",false);
                    break;

                case "lead_in_shang":
                    layer.open({
                        type: 1,//外部页面为2，内部层1
                        title: "<span style='color:white' align='center'><i class='layui-icon'>&#xe61f;</i> 导入交易数据</span>",
                        area: ['30%', '30%'],
                        fix: false,
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'layui-layer-lan',
                        content:$("#lead-in").html(),
                        anim: 1
                    });
                    //JS校验form表单信息
                function checkData(){
                    var fileDir = $("#upfile").val();
                    var suffix = fileDir.substr(fileDir.lastIndexOf("."));
                    if("" == fileDir){
                        alert("选择需要导入的Excel文件！");
                        return false;
                    }
                    if(".xls" != suffix && ".xlsx" != suffix ){
                        alert("选择Excel格式的文件导入！");
                        return false;
                    }
                    return true;
                }
                    break;
            }
        });

        //监听表格行工具(操作)事件 [不能和前面写在一起，原因二者参数有区别：前者toolbar，这里为tool]
        table.on("tool(MarketList)",function (obj) {
            //得到表格行数据
            var data=obj.data;
            //判断事件event值，与lay-event属性比较(使用switch或if梯形结构都可以,前面已经用过switch,
            // 此处使用if梯形结构)
            //判断是否为行修改操作
            if(obj.event == "update"){
                //将设置表单操作方式为修改
                method="update";
                //设置界面信息
                layer.open({
                    type: 1,
                    title:'<span style=\'color:white\' align=\'center\'><i class=\'layui-icon\'>&#xe6b2;</i>修改存款业务</span>',
                    area: ['40%', '70%'],
                    shade: 0.4,
                    skin: 'layui-layer-lan',
                    content: $("#data-main").html()
                });
                //alert(data.empName+","+data.hiredate);
                //将当前行数据显示在表单各字段中
                form.val("EquityFormTest", {
                    "MarketId": data.MarketId,
                    "seId":data.seId,
                    "inputDate":data.inputDate,
                    "openPrice":data.openPrice,
                    "closePrice":data.closePrice,
                    "notes":data.notes,
                });
                //将主键设置成只读:不允许修改
                $("input[name='rightsId']").prop("readonly","readonly");
            }
        });
    });
</script>
</body>
</html>